package com.qys.livesMall.shortVideo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qys.livesMall.shortVideo.mapper.MusicLibraryMapper;
import com.qys.livesMall.shortVideo.model.dto.app.QueryMusicLibraryDTO;
import com.qys.livesMall.shortVideo.model.entity.MusicLibrary;
import com.qys.livesMall.shortVideo.model.vo.app.MusicLibraryVO;
import com.qys.livesMall.shortVideo.service.MusicLibraryService;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * 音乐库信息表(MusicLibrary)表服务实现类
 *
 * @author makejava
 * @since 2023-09-05 16:08:51
 */
@Service("musicLibraryService")
public class MusicLibraryServiceImpl extends ServiceImpl<MusicLibraryMapper, MusicLibrary> implements MusicLibraryService {

    @Override
    public IPage<MusicLibraryVO> selectAll(QueryMusicLibraryDTO dto) {
        return baseMapper.selectPage(new Page<>(dto.getPageNum(), dto.getPageSize()), Wrappers.lambdaQuery()).convert(e -> {
            MusicLibraryVO vo = new MusicLibraryVO();
            BeanUtil.copyProperties(e, vo);
            return vo;
        });
    }

    @Override
    public MusicLibraryVO selectOne(Serializable id) {
        MusicLibrary musicLibrary = baseMapper.selectById(id);
        if(musicLibrary != null){
            MusicLibraryVO vo = new MusicLibraryVO();
            BeanUtil.copyProperties(musicLibrary, vo);
            return vo;
        }
        return null;
    }
}

